import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import vuexPersist from "vuex-persist";
export default new Vuex.Store({
  state: {
    list: [
      {
        title: "商品1",
        price: 100,
        id: 1001,
        num: 5,
      },
      {
        title: "商品2",
        price: 200,
        id: 1002,
        num: 5,
      },
      {
        title: "商品3",
        price: 300,
        id: 1003,
        num: 6,
      },
      {
        title: "商品4",
        price: 100,
        id: 1004,
        num: 3,
      },
    ],
  },
  mutations: {
    removes(state, sel) {
      state.list = state.list.filter((item) => {
        return sel.includes(item) == false;
      });

      //把不删的数据筛选出来留下来,直接在sel中看这条数据是不是存在，如果存在证明是要删除的，不存在 就留下来
    },
  },
  actions: {},
  modules: {},
  plugins: [
    new vuexPersist({
      localstorage: window.localStorage,
    }).plugin,
  ],
});
